Trò chơi đua xe động vật trong UNITY Engine
114.844 lượt xem;
- Ref.cs
- Spriter /
- Editor /
- Spriter2Unity /
- ThirdParty /
- Assets /
- project /
1 /*
2 Copyright (c) 2014 Andrew Jones, Dario Seyb
3 Based on 'Spriter2Unity' python code by Malhavok
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23 using System;
24 using System.Collections.Generic;
25 using System.Linq;
26 using System.Text;
27 using System.Xml;
28 using UnityEngine;
29
30 namespace Assets.ThirdParty.Spriter2Unity.Editor.Spriter
31 {
32 public class Ref : KeyElem
33 {
34 public MainlineKey MainlineKey { get; private set; }
35 protected SpatialInfo unmapped;
36 public TimelineKey Referenced { get; private set; }
37 public BoneRef Parent { get; private set; }
38 public string RelativePath
39 {
40 get
41 {
42 if(Parent == null)
43 {
44 return Referenced.Timeline.Name;
45 }
46 else
47 {
48 return Parent.RelativePath + "/" + Referenced.Timeline.Name;
49 }
50 }
51 }
52
53 public SpatialInfo Unmapped
54 {
55 get
56 {
57 if (unmapped == null)
58 {
59 unmapped = ComputeUnmapped();
60 }
61 return unmapped;
62 }
63 }
64
65 private SpatialInfo ComputeUnmapped()
66 {
67 SpatialInfo spatialInfo = null;
68 var spatial = Referenced as SpatialTimelineKey;
69 if (spatial != null)
70 {
71 spatialInfo = spatial.Spatial;
72 }
73 else
74 {
75 Debug.LogError("Non-Spatial Ref type!!");
76 }
77
78 if (Parent != null)
79 {
80 spatialInfo = spatialInfo.Unmap (Parent.Unmapped);
81 }
82
83 return spatialInfo;
84 }
85
86 public Ref(XmlElement element, SpriterAnimation animation, MainlineKey parentKey)
87 :base(element)
88 {
89 MainlineKey = parentKey;
90 Parse(element, animation, parentKey);
91 }
92
93 private void Parse(XmlElement element, SpriterAnimation animation, MainlineKey parentKey)
94 {
95 Referenced = GetTimelineKey(element, animation);
96
97 int parentId = element.GetInt("parent", -1);
98 if(parentId >= 0)
99 {
100 Parent = parentKey.GetBoneRef(parentId);
101 }
102 }
103
104 protected TimelineKey GetTimelineKey(XmlElement element, SpriterAnimation animation)
105 {
106 int timeline = element.GetInt("timeline", 0);
107 int key = element.GetInt("key", 0);
108
109 var timelineObj = animation.GetTimeline(timeline);
110 if (timelineObj == null)
111 {
112 Debug.LogError(String.Format(
113 System.Globalization.CultureInfo.InvariantCulture,
114 "Unable to find timeline {0} in animation {1}",
115 timeline,
116 animation.Id));
117 }
118 return timelineObj.GetKey(key);
119 }
120 }
121 }
2 Copyright (c) 2014 Andrew Jones, Dario Seyb
3 Based on 'Spriter2Unity' python code by Malhavok
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
22 */
23 using System;
24 using System.Collections.Generic;
25 using System.Linq;
26 using System.Text;
27 using System.Xml;
28 using UnityEngine;
29
30 namespace Assets.ThirdParty.Spriter2Unity.Editor.Spriter
31 {
32 public class Ref : KeyElem
33 {
34 public MainlineKey MainlineKey { get; private set; }
35 protected SpatialInfo unmapped;
36 public TimelineKey Referenced { get; private set; }
37 public BoneRef Parent { get; private set; }
38 public string RelativePath
39 {
40 get
41 {
42 if(Parent == null)
43 {
44 return Referenced.Timeline.Name;
45 }
46 else
47 {
48 return Parent.RelativePath + "/" + Referenced.Timeline.Name;
49 }
50 }
51 }
52
53 public SpatialInfo Unmapped
54 {
55 get
56 {
57 if (unmapped == null)
58 {
59 unmapped = ComputeUnmapped();
60 }
61 return unmapped;
62 }
63 }
64
65 private SpatialInfo ComputeUnmapped()
66 {
67 SpatialInfo spatialInfo = null;
68 var spatial = Referenced as SpatialTimelineKey;
69 if (spatial != null)
70 {
71 spatialInfo = spatial.Spatial;
72 }
73 else
74 {
75 Debug.LogError("Non-Spatial Ref type!!");
76 }
77
78 if (Parent != null)
79 {
80 spatialInfo = spatialInfo.Unmap (Parent.Unmapped);
81 }
82
83 return spatialInfo;
84 }
85
86 public Ref(XmlElement element, SpriterAnimation animation, MainlineKey parentKey)
87 :base(element)
88 {
89 MainlineKey = parentKey;
90 Parse(element, animation, parentKey);
91 }
92
93 private void Parse(XmlElement element, SpriterAnimation animation, MainlineKey parentKey)
94 {
95 Referenced = GetTimelineKey(element, animation);
96
97 int parentId = element.GetInt("parent", -1);
98 if(parentId >= 0)
99 {
100 Parent = parentKey.GetBoneRef(parentId);
101 }
102 }
103
104 protected TimelineKey GetTimelineKey(XmlElement element, SpriterAnimation animation)
105 {
106 int timeline = element.GetInt("timeline", 0);
107 int key = element.GetInt("key", 0);
108
109 var timelineObj = animation.GetTimeline(timeline);
110 if (timelineObj == null)
111 {
112 Debug.LogError(String.Format(
113 System.Globalization.CultureInfo.InvariantCulture,
114 "Unable to find timeline {0} in animation {1}",
115 timeline,
116 animation.Id));
117 }
118 return timelineObj.GetKey(key);
119 }
120 }
121 }